package com.wjy.common.mybatisplus;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @author ybxxszl
 * @desc 自动填充
 * @data 2019年4月12日
 */
@Component
public class FieldFillConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        this.setInsertFieldValByName("logicDelete", 0, metaObject);
        this.setInsertFieldValByName("version", 0, metaObject);
        this.setInsertFieldValByName("insertId", "insertId", metaObject);
        this.setInsertFieldValByName("insertTime", new Date(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setUpdateFieldValByName("updateId", "updateId", metaObject);
        this.setUpdateFieldValByName("updateTime", new Date(), metaObject);
    }

}
